using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Crossborder.Common.Utility.Encrypt
{
    public class MD5Helper
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string MD5EncryptFor16(string param)
        {
            var md5 = MD5.Create();
            string encryptStr = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(param)), 4, 8);
            encryptStr = encryptStr.Replace("-", string.Empty);
            return encryptStr;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string MD5EncryptFor32(string param = "")
        {
            string encryptStr = string.Empty;
            try
            {
                if (!string.IsNullOrEmpty(param) && !string.IsNullOrWhiteSpace(param))
                {
                    var md5 = MD5.Create();
                    byte[] btyes = md5.ComputeHash(Encoding.UTF8.GetBytes(param));
                    foreach (var item in btyes)
                    {
                        encryptStr = string.Concat(encryptStr, item.ToString("X2"));
                    }
                }
            }
            catch
            {

            }
            return encryptStr;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string MD5EncryptFor64(string param)
        {
            return default;
        }
    }
}